package cn.tedu.sp04.order.feign;

import cn.tedu.sp01.pojo.Item;
import cn.tedu.web.util.JsonResult;
import org.checkerframework.checker.units.qual.A;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
@Component
public class ItemClientFB implements ItemClient {
    @Override
    public JsonResult<List<Item>> getItems(String orderId) {
        //模拟有缓存数据
        //有缓存返回缓存
        if (Math.random() < 0.5) {
             ArrayList<Item> list = new ArrayList<>();
             list.add(new Item(1,"缓存商品1",2));
            list.add(new Item(2,"缓存商品2",1));
            list.add(new Item(3,"缓存商品3",5));
            list.add(new Item(4,"缓存商品4",4));
            list.add(new Item(5,"缓存商品5",2));
            list.add(new Item(6,"缓存商品6",2));

        }

        //没有缓存返回错误提示
        return JsonResult.err().msg("获取订单商品列表失败");
    }

    @Override
    public JsonResult<?> decreaseNumber(List<Item> items) {
        return JsonResult.err().msg("减少商品库存失败");
    }
}
